home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / ulib / polybounds.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  965b  |  48 lines

  1. /***********************************************************************
  2.  * $Id: polybounds.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
  3.  *
  4.  *.  Copyright(c) 1993,1994 by T.C. Zhao
  5.  *   All rights reserved.
  6.  *.
  7.  *
  8.  ***********************************************************************/
  9. #if !defined(lint) && defined(F_ID)
  10. char *id_pb = "$Id: polybounds.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
  11. #endif
  12.  
  13. #include "ulib.h"
  14.  
  15. Rect_t *
  16. spoly_bounds(short *x, short *y, int n)
  17. {
  18.     static Rect_t brect[5];
  19.     static int nb;
  20.     Rect_t *b = brect + nb++;
  21.  
  22.     int xmin = x[0], xmax = x[0];
  23.     int ymin = y[0], ymax = y[0];
  24.     int i;
  25.  
  26.     for (i = 1; i < n; i++)
  27.       {
  28.       if (x[i] < xmin)
  29.           xmin = x[i];
  30.       else if (x[i] > xmax)
  31.           xmax = x[i];
  32.  
  33.       if (y[i] < ymin)
  34.           ymin = y[i];
  35.       else if (y[i] > ymax)
  36.           ymax = y[i];
  37.       }
  38.  
  39.     b->x = xmin;
  40.     b->y = ymin;
  41.     b->w = xmax - xmin + 1;
  42.     b->h = ymax - ymin + 1;
  43.  
  44.     nb %= 5;
  45.  
  46.     return b;
  47. }
  48.